//
//  BaseNavigationController.m
//  BulgeFramework
//
//  Created by beisheng03 on 2018/2/23.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()<UINavigationBarDelegate,UIGestureRecognizerDelegate>

@end

@implementation BaseNavigationController


+ (void)initialize
{
    if (self == [BaseNavigationController class]) {
        
        UINavigationBar *gationBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
        
        UIBarButtonItem *barItem = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
        
        NSMutableDictionary *testAttrNor = [NSMutableDictionary dictionary];
        
        // 描述字体
        testAttrNor[NSFontAttributeName] = MYFONT(15);
        
        // 设置标题的富文本属性
        [barItem setTitleTextAttributes:testAttrNor forState:UIControlStateNormal];
        
        gationBar.tintColor = [UIColor whiteColor];
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        
        dic[NSFontAttributeName] = MYFONT(17);
        
        dic[NSForegroundColorAttributeName] = [UIColor whiteColor];
        
        [gationBar setTitleTextAttributes:dic];
        
        
        
        [gationBar setBackgroundImage:[UIImage imageWithMyColor:[UIColor colorWithRed:38.0/255.0 green:133.0/255.0  blue:216.0/255.0 alpha:0.9]] forBarMetrics:UIBarMetricsDefault];
    /*
        [gationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
        
        [gationBar setBackgroundImage:[UIImage imageWithMyColor:[UIColor colorWithRed:0.0/255.0 green:153.0/255.0  blue:255.0/255.0 alpha:0.98]] forBarMetrics:UIBarMetricsDefault];
      */
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    id target = self.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    
    self.interactivePopGestureRecognizer.enabled = NO;
    // Do any additional setup after loading the view.
}

- (void)handleNavigationTransition:(UIGestureRecognizer *)giseture{}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 只有非根控制器,才需要设置返回按钮
    // 0
    if (self.childViewControllers.count > 0 ) { // 非根控制器
        
        viewController.hidesBottomBarWhenPushed = YES;
       
        
    }
    
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    [super pushViewController:viewController animated:animated];
}


//- (void)back{
//
//
//    [self popViewControllerAnimated:YES];
//}


#pragma mark - UIGestureRecognizerDelegate
// 是否触发手势
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
   
        return self.childViewControllers.count > 1;
        

    
}



- (UIStatusBarStyle)preferredStatusBarStyle{
    
    
    return UIStatusBarStyleLightContent;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc{
    
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
